<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | Centrifugo 接口
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\exception\LogicException;
use common\service\CentrifugalService;
use think\Request;

class CentrifugalController extends VerifyController
{
    public $centrifugalService;

    public function __construct()
    {
        parent::__construct();
        $this->centrifugalService = CentrifugalService::getInstance();
    }

    /**
     * 发送消息到自己的通道
     * @param Request $request
     * @return \think\Response
     */
    public function sendDataToMineChannel(Request $request)
    {
        try {
            $param = $request->param();
            $res = $this->centrifugalService->sendDataToMineChannel($param['data'], $request->getUserId());
            return json(success_response('', $res));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }
}
